package com.wz.project.print;

import com.alibaba.fastjson.JSONObject;
import com.wz.device.entity.BasCargoSpace;
import com.wz.device.mapper.BasCargoSpaceMapper;
import com.wz.device.service.BasCargoSpaceService;
import com.wz.project.ddjmsg.domain.MsgDdj;
import com.wz.project.ddjmsg.service.IMsgDdjService;
import com.wz.project.kpi.Cargo;
import com.wz.project.mydo.domain.MydoJob;
import com.wz.project.mydo.domain.MydoJobDetail;
import com.wz.project.mydo.mydojob.service.IMydoJobService;
import com.wz.project.mydo.mydojobdetail.service.IJobDetailService;
import com.wz.project.outStock.stockout.service.IOutStockoutService;
import com.wz.project.ssj.domain.MsgSsj;
import com.wz.project.ssj.service.IMsgSsjService;
import com.wz.project.tsjJob.domain.ViewJobTsj;
import com.wz.project.tsjJob.service.IViewJobTsjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/print")
public class PrintController {

    private String prefix = "print";

    @Autowired
    private IMydoJobService mydoJobService;

    @Autowired
    private IJobDetailService jobDetailService;

    @Autowired
    private IViewJobTsjService jobTsjService;

    @Autowired
    private IMsgSsjService msgSsjService;

    @Autowired
    private IMsgDdjService msgDdjService;

    @Autowired
    private BasCargoSpaceService basCargoSpaceService;

    @Autowired
    private BasCargoSpaceMapper basCargoSpaceMapper;

    @GetMapping("/printOne")
    public String printOne() {
        return prefix + "/printOne";
    }

    @GetMapping("/printTwo")
    public String printTwo() {
        return prefix + "/printTwo";
    }

    @GetMapping("/printThree")
    public String printThree() {
        return prefix + "/printThree";
    }

    @GetMapping("/printFour")
    public String printFour() {
        return prefix + "/printFour";
    }

    @GetMapping("/printFive")
    public String printFive() {
        return prefix + "/printFive";
    }

    @GetMapping("/printSix")
    public String printSix() {
        return prefix + "/printSix";
    }


    //一号屏

    /**
     * 生成入库作业
     */
    @RequestMapping("/list1")
    @ResponseBody
    public Map<String, List> list1(@RequestBody JSONObject jsonObject) {
        Object id = jsonObject.get("id");
        Map<String, List> map = new HashMap();
        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-"+id);
        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size() == 0) {
            MsgDdj msgDdj = new MsgDdj();
            msgDdj.setName("堆垛机");
            List<MsgDdj> msgDdjs = msgDdjService.selectMsgDdjList(msgDdj);
            for (int i = 1; i < 3; i++) {
                Integer status = basCargoSpaceMapper.findByStatus(i + "");
                ArrayList arrayList = new ArrayList();
                arrayList.add(status);
                map.put("s" + i, arrayList);
            }
            map.put("viewJobTsjs",null);
            map.put("msgDdjs", msgDdjs);
            return map;
        }
        if (viewJobTsjs.size()>0){
            viewJobTsjs.get(0).setNum(String.valueOf(viewJobTsjs.size()));
        }
        map.put("viewJobTsjs", viewJobTsjs);
        return map;
    }


    //一号屏
    @RequestMapping("/list")
    @ResponseBody
    public List<ViewJobTsj> list(String inOrOut) {
        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-1");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

    //二号屏
    @RequestMapping("/list2")
    @ResponseBody
    public List<ViewJobTsj> list2(String inOrOut) {

        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-2");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

    //三号屏
    @RequestMapping("/list3")
    @ResponseBody
    public List<ViewJobTsj> list3(String inOrOut) {

        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-3");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

    //四号屏
    @RequestMapping("/list4")
    @ResponseBody
    public List<ViewJobTsj> list4(String inOrOut) {

        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-4");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

    //五号屏
    @RequestMapping("/list5")
    @ResponseBody
    public List<ViewJobTsj> list5(String inOrOut) {

        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-5");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

    //六号屏
    @RequestMapping("/list6")
    @ResponseBody
    public List<ViewJobTsj> list6(String inOrOut) {

        MsgSsj msgSsj1 = msgSsjService.selectMsgSsjById("TSJCKDW-6");

        ViewJobTsj viewJobTsj = new ViewJobTsj();
        viewJobTsj.setTaskNo(String.valueOf(msgSsj1.getTaskNo()));
        List<ViewJobTsj> viewJobTsjs = jobTsjService.selectViewJobTsjList(viewJobTsj);
        if (viewJobTsjs.size()>0){
            for (int i = 0; i <viewJobTsjs.size() ; i++) {
                if (i==0){
                    viewJobTsjs.get(i).setNum(String.valueOf(viewJobTsjs.size()));
                }else {
                    viewJobTsjs.get(i).setNum("");
                }
            }
        }
        return viewJobTsjs;
    }

}
